/* -----------------
* brief
* 1. this is code gen by tools
 */

package middleware

import (
	"github.com/mjiulee/lego"
	_ "github.com/mjiulee/lego/utils"
	"github.com/valyala/fasthttp"
	. "saas_sys_base/modules/tenant/controller"
	"strings"
)

//type MiddlewareHandle func(next fasthttp.RequestHandler) fasthttp.RequestHandler

var TenantCheckMiddleware lego.MiddlewareHandle = func(next fasthttp.RequestHandler) fasthttp.RequestHandler {
	return fasthttp.RequestHandler(func(ctx *fasthttp.RequestCtx) {
		ctxExt := &lego.RequestCtxExtent{ctx}
		if strings.HasPrefix(string(ctxExt.Path()), "/api/sys") {
			next(ctx)
			return
		}
		tenantApiCtrl := GetInstanceTenantApiCtrl()
		err := tenantApiCtrl.CheckPermission(ctx)
		if err != nil {
			return //中间间处理函数内已经设置reponse消息了
		}
		next(ctx)
		return

	})
}
